package com.xinqi.modules.user.users.ueuse.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.user.users.ueuse.domain.UserUseLogEntity;
import com.xinqi.modules.user.user.ueuse.dto.req.UserUseCreateDTO;
import com.xinqi.modules.user.user.ueuse.dto.req.UserUseQueryDTO;
import com.xinqi.modules.user.user.ueuse.dto.rsp.UserUseDateResultDTO;
import com.xinqi.modules.user.user.ueuse.dto.rsp.UserUseResultDTO;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.mybatis.utils.Pages;
import com.xinqi.modules.user.users.ueuse.manager.UserUseLogManager;
import com.xinqi.modules.user.users.ueuse.service.UserUseLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 用户使用服务层
 * @author: dzy
 * @date: 2023/04/01
 */
@Validated
@Service
@RequiredArgsConstructor
public class UserUseLogServiceImpl implements UserUseLogService {

    private final UserUseLogManager userUseLogManager;


    @Override
    @DS("slaver")
    public PageInfo<UserUseDateResultDTO> datePage(Param param) {
        Long userId = LoginHelper.getUserId();
        IPage<UserUseDateResultDTO> page = userUseLogManager.datePage(param, userId);
        return Pages.convert(page);
    }

    @Override
    @DS("slaver")
    public PageInfo<UserUseResultDTO> page(UserUseQueryDTO query) {
        query.setUserId(LoginHelper.getUserId());
        IPage<UserUseResultDTO> page = userUseLogManager.page(query);
        return Pages.convert(page);
    }

    @Override
    @DS("slaver")
    public List<UserUseResultDTO> list(UserUseQueryDTO query) {
        query.setUserId(LoginHelper.getUserId());
        return userUseLogManager.list(query);
    }

    @Override
    public boolean addUserUseLog(UserUseCreateDTO create) {
        Long userId = LoginHelper.getUserId();
        UserUseLogEntity entity = new UserUseLogEntity();
        entity.setUserId(userId);
        entity.setType(create.getType());
        entity.setStyle(create.getStyle());
        return userUseLogManager.save(entity);
    }

}
